﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using EZCRS.HCMS.Bll.AIR;
using EZCRS.HCMS.Entity;
using System.Collections.Generic;
using EZCRS.HCMS.Bll.Report;

using dotnetCHARTING;
using System.Drawing;

namespace EZCRS.HCMS.report
{
    public partial class channel_grow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            int iYear1 = DateTime.Now.Year - 5;

            for (int i = iYear1; i <= DateTime.Now.Year; i++)
            {
                ddlYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            ddlYear.SelectedIndex = ddlYear.Items.Count - 1;

            EZCRS.HCMS.Bll.AIR.TAChannel channel = new TAChannel();

            List<Channel> lst = channel.GetAll();

            foreach (Channel cl in lst)
            {
                ddlChannel.Items.Add(new ListItem(cl.Name, cl.Name));
            }
        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            ShowReport(Convert.ToInt32(ddlYear.SelectedValue));
        }


        private void ShowReport(int Year)
        {

            SeriesCollection sc = new SeriesCollection();

            chrReport.Title = "预订产量渠道增长趋势图";

            chrReport.YAxis.Scale = Scale.Normal;

            chrReport.XAxis.Label.Text = Year.ToString();

            chrReport.YAxis.Label.Text = "渠道(间数)";

            chrReport.TempDirectory = "../temp";

            chrReport.Width = 700;
            chrReport.Height = 400;

            ReservationReport report = ReservationReport.getInstance();

            Series ser = new Series();
            ser.Name = ddlChannel.SelectedValue;

            for(int i = 1; i<=12; i++)
            {
                int iChannelAmount = report.GetReserveMonthAmountByChannel(Year, i, ddlChannel.SelectedValue);

                Element el = new Element();

                el.Name = i.ToString() + "月";

                el.YValue = iChannelAmount;

                el.ShowValue = true;

                ser.Elements.Add(el);

            }

            sc.Add(ser);

            sc[0].DefaultElement.Color = Color.FromArgb(49, 255, 255);
            sc[0].Type = SeriesType.Line;   

            chrReport.SeriesCollection.Add(sc);

        }

    }
}
